package com.example.larouzey.zyfyp_201.model;

import com.example.larouzey.zyfyp_201.bean.LoginBean;
import com.example.larouzey.zyfyp_201.iface.Registeriface;
import com.example.larouzey.zyfyp_201.iface.Registerlistener;
import com.example.larouzey.zyfyp_201.service.RegisterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.Callback;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Larouzey on 2017/5/3.
 */

public class Registermodel implements Registeriface{
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    public Registermodel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void getResultList(String username , String password , final Registerlistener listener){
        RegisterService registerService=retrofit.create(RegisterService.class);
        Call<List<LoginBean>> call = registerService.getResult(username,password);
        call.enqueue(new Callback<List<LoginBean>>(){

            @Override
            public void onResponse(Call<List<LoginBean>> call, Response<List<LoginBean>> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<List<LoginBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
